<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cetak OR</title>
<?php $this->load->helper('HTML');
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
</head>
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=cetak_or_babymanager.xls");
header("Pragma: no-cache");
header("Expires: 0");
?>
<body>
<table width="851" align="center">
	<tr class="detail2">
   	  <td width="849" align="center">
        <table width="850" align="center">
        <tr class="detail2">
          <td width="440" rowspan="4" valign="top"><img src="<?php echo base_url();?>images/logo.jpg" />&nbsp;</td>
          <td width="41">&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td width="41">&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr class="detail">
            <td colspan="2" >LAPORAN OVERIDING <?php echo strtoupper($nama_dealer->strnama_dealer) ?></td>
          <td>&nbsp;</td>
        </tr>
        <tr class="detail" >
            <td colspan="2">PERIODE : <?php echo strtoupper($nama_bulan) ?></td>
                <td>&nbsp;</td>
        </tr>
            <tr class="detail">
            <td colspan="2">CABANG : <?php echo strtoupper($nama_dealer->strnama_cabang)?></td>
                <td>&nbsp;</td>
        </tr>
    </table>    </td>
    <tr>
    	<td align="center">
        	<table width="851" border="1" align="center"  class="detail" style="font-size:9px">
			<tr class="detail2">
                	<th width="65" rowspan="4">DEALER</th>
                    <th width="44" rowspan="4">UNIT</th>
                    <th width="60" rowspan="4">STATUS</th>
            </tr>
            <tr>
            <th colspan="3">TOTAL SALES</th>
                   <th width="87" rowspan="3">HARGA DEALER</th>
                    <th width="93" rowspan="3">OVERIDING</th>
                    <th width="66" rowspan="3">(Pph 5%)</th>
                    <th width="76" rowspan="3">JUMLAH</th>
			</tr>
            <tr>
            <th width="85" rowspan="2">PERSONAL</th>
            <th colspan="2">SALES GROUP</th>
            </tr>
            <tr>
            	<th width="71">20%</th>
                <th width="67">10%</th>
            </tr>
            <tr>
                    <td align="left"><?php echo $data_omset[0]->strnama_dealer?></td>
                    <td align="left"><?php echo $data_omset[0]->strnama_unit?></td>
                    <td align="left">Manager</td>
                    <td align="left"><?php echo $data_omset[0]->total_omset;?></td>
                    <td align="left"><?php echo $data_omset_group[0]->omset20;?></td>
                    <td align="left"><?php echo $data_omset_group[0]->omset10;?></td>
                    <td align="left"><?php 
					//perhitungan yang lama
					//$hargadealermanager = $data_omset[0]->omset20 * 80/100 + $data_omset[0]->omset10 * 90/100;
					$hargadealermanager = $data_omset_group[0]->omset20 * 80/100 + $data_omset_group[0]->omset10 * 90/100;
					echo $hargadealermanager;?></td>
                    
                    <td align="left"><?php 
					$ormanager = ($hargadealermanager * 3 )/ 100;
					echo $ormanager;?></td>
                    <td align="left"><?php $pphmanager = ( $ormanager* 5)/100; echo $pphmanager;?></td>
                    <td align="left"><?php $terimamanager = $ormanager - $pphmanager; echo $terimamanager;?></td>
                </tr>
            
                <?php
                $total = 0;
                $no=1;
                $tot10=0;
                $tot20=0;
                $har=0;
                $over=0;
                $cash=0;
                $diskon=0;
                $tpph=0;
				$tterima=0;
                foreach($data_pv_manager as  $d):
				$id_baby = $this->Penjualan_model->get_baby_manager($data_omset[0]->intid_unit);
                ?>
                <tr>
                    <td align="left"><?php echo $d->strnama_dealer?></td>
                    <td align="left"><?php echo $d->strnama_unit?></td>
                    <td align="left">Dealer</td>
                    <td align="left">&nbsp;</td>
                    <td align="left"><?php echo $d->intomset20;?></td>
                    <td align="left"><?php echo $d->intomset10;?></td>
                    <td align="left"><?php 
					$hargadealer = $d->intomset20 * 80/100 + $d->intomset10 * 90/100;
					echo $hargadealer;?></td>
                    <td align="left"><?php 
					$or = ($hargadealer * 3 )/ 100;
					echo $or;?></td>
                    <td align="left"><?php $pph = ( $or* 5)/100; echo $pph;?></td>
                    <td align="left"><?php $terima = $or - $pph; echo $terima;?></td>
                </tr>
                <?php 
				$baby20 = 0;
				$baby10 = 0;
				$harbaby = 0;
				$orbaby = 0;
				$pphbaby = 0;
				$terimababy = 0;
				foreach($id_baby as $b):
				$totalbaby = $this->Penjualan_model->get_unittotal($b->intid_unitbaby, $id_bulan);
				?>
                <tr>
                	<td>&nbsp;</td>
                	<td><?php echo $b->strnama_unit?></td>
                    <td>Baby Mngr</td>
                    <td><?php echo (!empty($totalbaby->inttotal_bayar)?$totalbaby->inttotal_bayar:'0')?></td>
                    <td><?php echo (!empty($totalbaby->intomset20)?$totalbaby->intomset20:'0')?></td>
                    <td><?php echo (!empty($totalbaby->intomset10)?$totalbaby->intomset10:'0')?></td>
                    <td><?php echo (!empty($totalbaby->inttotal_bayar)?($totalbaby->intomset20 * 80/100 + $totalbaby->intomset10 * 90/100):'0')?></td>
                    <td><?php echo (!empty($totalbaby->inttotal_bayar)?$totalbaby->inttotal_bayar * 3 / 100:'0')?></td>
                    <td><?php echo (!empty($totalbaby->inttotal_bayar)?($totalbaby->inttotal_bayar * 3 / 100)*5 / 100:'0')?></td>
                    <td><?php echo (!empty($totalbaby->inttotal_bayar)?$totalbaby->inttotal_bayar * 3 / 100 - ($totalbaby->inttotal_bayar * 3 / 100)*5 / 100:'0')?></td>
                </tr>
                <?php 
				$baby20 = $baby20 + $totalbaby->intomset20;
				$baby10 = $baby10 + $totalbaby->intomset10;
				$harbaby = $harbaby + ($totalbaby->intomset20 * 80/100 + $totalbaby->intomset10 * 90/100);
				$orbaby = $orbaby + ($totalbaby->inttotal_bayar * 3 / 100);
				$pphbaby = $pphbaby + (($totalbaby->inttotal_bayar * 3 / 100)*5 / 100);
				$terimababy = $terimababy + ($totalbaby->inttotal_bayar * 3 / 100 - ($totalbaby->inttotal_bayar * 3 / 100)*5 / 100);
				endforeach;?>
                <?php $no++; 
					$tot10 = $tot10 + $d->intomset10;
                    $tot20 = $tot20 + $d->intomset20;
                    $har = $har + $hargadealer;
                    $over = $over + $or;
                    $cash = $cash + $d->intcash;
                   	$tpph= $tpph + $pph;
					$tterima = $tterima + $terima;
				endforeach;?>

                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
               
                <tr>
                	<td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>TOTAL</td>
                 	<td align="left"><?php $total20 = $data_omset_group[0]->omset20 + $tot20 + $baby20; echo $total20;?></td>
                    <td align="left"><?php $total10 = $data_omset_group[0]->omset10 + $tot10 + $baby10; echo $total10;?></td>
                 	<td align="left"><?php $totalhar = $hargadealermanager + $har + $harbaby; echo $totalhar;?></td>
                    <td align="left"><?php $totalor = $ormanager + $over + $orbaby; echo $totalor;?></td>
                    <td align="left"><?php $totalpph = $pphmanager + $tpph + $pphbaby; echo $totalpph;?></td>
                    <td align="left"><?php $totalterima = $terimamanager + $tterima + $terimababy; echo $totalterima;?></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>BONUS PLUS</td>
                  <td align="left">&nbsp;</td>
                  <td align="left">&nbsp;</td>
                  <td align="left">&nbsp;</td>
                  <td align="left"><?php 
				  $totalgroup = $total20 + $total10;
				  if ($totalgroup>6000000 and $totalgroup<=7999999) 
				  {
				  	$bonusplus = 120000;
				  } else if ($totalgroup>8000000 and $totalgroup<=9999999) 
				  {
				  	$bonusplus = 200000;
				  } else if ($totalgroup>10000000 and $totalgroup<=14999999)  
				  {
				  	$bonusplus = 275000;
				  } else if ($totalgroup>15000000 and $totalgroup<=19999999)
				  {
				  	$bonusplus = 450000;
				  } else if ($totalgroup>20000000 and $totalgroup<=24999999) 
				  {
				  	$bonusplus = 650000;
				  } else if ($totalgroup>25000000 and $totalgroup<=29999999)
				  {
				  	$bonusplus = 875000;
				  } else if ($totalgroup>30000000 and $totalgroup<=34999999)
				  {
				  	$bonusplus = 1125000;
				  } else {
				  	$bonusplus = 0;
				  }
				  //echo "Rp. ".number_format($bonusplus,2 , ',' , '.');
				  echo $bonusplus;
				  ?></td>
                  <td align="left"><?php 
				  $dikurpph = ($bonusplus*5)/100;
				  //echo "Rp. ".number_format($dikurpph,2 , ',' , '.');
				  echo $dikurpph;
				  ?>
				  </td>
                  <td align="left"><?php 
				  $totalbonus = $bonusplus - $dikurpph;
				  //echo "Rp. ".number_format($totalbonus,2 , ',' , '.');
				  echo $totalbonus;
				  ?></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td><strong>GRAND TOTAL</strong></td>
                  <td align="left">&nbsp;</td>
                  <td align="left">&nbsp;</td>
                  <td align="left">&nbsp;</td>
                  <td align="left">&nbsp;</td>
                  <td align="left">&nbsp;</td>
                  <td align="left"><?php 
				  //salah kode
				 // $grandtotal = $totalbonus - $tterima;
				  $grandtotal = $totalterima+$totalbonus;
				  //echo "Rp. ".number_format($grandtotal,2 , ',' , '.');
				  echo $grandtotal;
				  ?></td>
                </tr>
				 <tr>
                  <td colspan="10">&nbsp;</td>
                  </td>
				  <tr>
				  <?php
				  if(!empty($baby)){
					  $or = 0;
					  $pph = 0;
					  $terima = 0;
					  echo "<tr>
					  <th colspan='10' align='center'>OR Baby Manager</th>
					  </tr>";
						foreach($baby as $row){
						  $or = ($row->inttotal_bayar * 3 )/ 100;
						  $pph = ($or *5)/100;
						  $terima = $or-$pph;
						  echo "<tr><td>&nbsp;</td>
						  <td>".$row->strnama_unit."</td>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td>".$row->omset10."</td>
						  <td>".$row->omset20."</td>
						  <td>".$row->inttotal_bayar."</td>
						  <td>".$or."</td>
						  <td>".$pph."</td>
						  <td>".$terima."</td></tr>";
						  }
					  }else{
					  	echo "<td colspan='10' align='center'>Tidak mempunyai baby manager</td>";
					  }
					  ?>
				  </tr>
               </table>      
      </td>
    </tr>
    <!--<tr>
    <td>
    REKRUT PRIBADI BARU
    </td>
    </tr>
    <tr>
    <td>
      <table width="851" border="1" align="center"  class="detail" style="font-size:9px">
        <tr class="detail2">
          <th>DEALER</th>
          <th>PERSONAL</th>
        </tr>
        <?php 
			//foreach($rekrut as  $row):
		?>
        <tr>
          <td><?php //echo $row->strnama_dealer;?></td>
          <td><?php //echo "Rp. ".number_format($row->omset,2 , ',' , '.');?></td>
        </tr>
        <?php //endforeach;?>
      </table>    </td>
    </tr>
                <tr>
                	<td align="center"><table width="850" align="center" >
                        <tr class="detail">
                          <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td align="center">DIBUAT OLEH</td>
                          <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td align="center">DIPERIKSA OLEH</td>
                          <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td align="center">DITERIMA OLEH</td>
                          <td>&nbsp;</td>
						</tr>
                        <tr>
                          <td width="229" colspan="4" align="right">&nbsp;</td>
                          <td width="229" colspan="4" align="right">&nbsp;</td>
                          <td width="229" colspan="4" align="right">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width="229" colspan="4" align="right">&nbsp;</td>
                          <td width="229" colspan="4" align="right">&nbsp;</td>
                          <td width="229" colspan="4" align="right">&nbsp;</td>
                        </tr>
                        <tr>
                          <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td align="center">(....................)</td>
                          <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td align="center">(....................)</td>
                          <td>&nbsp;</td>
						  <td></td>
  </tr>
  -->
</table>
</body>
</html>